'use strict';

const Controller = require('egg').Controller;
const Mock = require('mockjs')

class HomeController extends Controller {
    async index() {
        const { ctx, app } = this;
        const data = Mock.mock({
            'list|50': [{
                'man': '@cname',
                'open': '@datetime()',
                'close': '@datetime()',
                'title': '@ctitle',
                'state|0-1': 1,
                'url': '@image(200x200, @color)',
                'look|0-100': 1,
                'path': '@url'
            }]
        })
        data.list.map(async(v) => {
            const item = {
                ...v,
                open: new Date(v.open).getTime(),
                close: new Date(v.close).getTime()
            }
            await app.mysql.insert('live', {...item })
        })
        ctx.body = data.list;
    }
}

module.exports = HomeController;